package com.example.shop_2211.fgViewModel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.GoodsEntityResult
import com.example.base.entity.IndexEntityResult
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class HomeViewModel:BaseViewModel() {
    val indexSuccess = MutableLiveData<IndexEntityResult>()
    val indexFail = MutableLiveData<String>()
    fun index(){
        viewModelScope.launch {
            try {
                indexSuccess.value = apiService.index()
            }catch (e:Exception){
                indexFail.value = e.message
            }
        }
    }
    val indexGoodsSuccess = MutableLiveData<GoodsEntityResult>()
    val indexGoodsFail = MutableLiveData<String>()
    fun indexGoods(type:Int,limit:Int,page:Int){
        viewModelScope.launch {
            try {
                indexGoodsSuccess.value = apiService.indexGoods(type, limit, page)
            }catch (e:Exception){
                indexGoodsFail.value = e.message
            }
        }
    }
}